package com.zengde.ai_sandbox.service.strategy.impl;

import com.zengde.ai_sandbox.context.OrderContext;
import com.zengde.ai_sandbox.context.OrderContextHolder;
import com.zengde.ai_sandbox.entity.Order;
import org.springframework.stereotype.Service;


@Service("alipayPayment") // 指定Bean名称，这将作为Map的key
public class AlipayPaymentStrategy extends AbstractPaymentStrategy {
    @Override
    public String getType() {
        return "ALIPAY";
    }
    
    // 2. 调用远程接口
    @Override
    public void invokeRmtInterface() {
        OrderContext orderContext = OrderContextHolder.getOrderContextTL();
        Order order = orderContext.getOrder();
        
        // 模拟调用支付宝支付接口
        System.out.println("正在调用支付宝支付接口: 订单号=" + order.getOrderNo() + ", 支付金额=" + order.getPaymentAmount());
        
        // 模拟网络延迟
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        // 模拟生成支付ID
        String paymentId = "alipay_" + System.currentTimeMillis();
        orderContext.setPaymentId(paymentId);
        orderContext.setActualPaymentAmount(order.getPaymentAmount());
        
        System.out.println("支付宝支付接口调用成功: paymentId=" + paymentId);
    }

    // 支付宝支付特殊逻辑
    @Override
    public void executePaymentSpecialLogic() {
        OrderContext orderContext = OrderContextHolder.getOrderContextTL();
        Order order = orderContext.getOrder();
        
        System.out.println("执行支付宝支付特殊逻辑: 订单号=" + order.getOrderNo());
        
        // 支付宝支付特殊处理逻辑
        System.out.println("1. 生成支付宝支付链接");
        System.out.println("2. 验证支付宝支付配置");
        System.out.println("3. 检查支付宝支付限额");
        
        // 模拟特殊逻辑处理时间
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        System.out.println("支付宝支付特殊逻辑执行完成");
    }

}